//
//  YYEProbleViewController.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/5.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYEProbleViewController.h"
#import "UITextView+Placeholder.h"

@interface YYEProbleViewController ()

@property (nonatomic,strong) UIImageView *contentView;
@property (nonatomic,strong) UITextView *textView;

@end

@implementation YYEProbleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"反馈";
    
    self.view.backgroundColor = GeneralBackColor;
    
    [self configNavi];
    
    [self configUI];
    
}

- (void)configNavi {
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStyleDone target:self action:@selector(sendClicked)];
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor blackColor]];
    
}

- (void)configUI {
    
    self.contentView = [[UIImageView alloc]init];
    self.contentView.image = [UIImage imageNamed:@"textBack"];
    self.contentView.userInteractionEnabled = YES;
    [self.view addSubview:self.contentView];
    
    self.textView = [[UITextView alloc]init];
    self.textView.placeholderLabel.font = [UIFont systemFontOfSize:13];
    self.textView.placeholderLabel.textColor = LineColor;
    self.textView.placeholder = @"请将您遇到的问题/建议反馈给我们。：）";
    self.textView.font = [UIFont systemFontOfSize:13];
    self.textView.showsVerticalScrollIndicator = NO;
    [self.contentView addSubview:self.textView];
    
    [self.contentView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.top);
        make.left.equalTo(self.view.left).offset(-4);
        make.right.equalTo(self.view.right).offset(4);
        make.height.equalTo(SCREEN_WIDTH / 2);
    }];
    
    [self.textView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(UIEdgeInsetsMake(12, 20, 6, 20));
    }];
    
}

// 发送
- (void)sendClicked {
    
    if (self.textView.text.length == 0) {
        [self.view makeToast:@"请输入内容"];
        return;
    }
    
    NSDictionary *dic = @{
                          @"uid":[LoginModel shareLogin].uid,
                          @"username":[LoginModel shareLogin].username,
                          @"token":[LoginModel shareLogin].token,
                          @"content":self.textView.text

                          };
    [SVProgressHUD show];
    [AFNHelper post:Feedback parameters:dic success:^(id responseObject) {
        
        
        if ([responseObject[@"status"] isEqual:@1]) {
            
            [self.navigationController popViewControllerAnimated:YES];
            
        }
        
        
        [SVProgressHUD showWithStatus:responseObject[@"message"]];
        [SVProgressHUD dismiss];
        
    } faliure:^(id error) {
        
        NSLog(@"请求失败");
        [SVProgressHUD showWithStatus:ShowError];
        [SVProgressHUD dismissWithDelay:0.5];
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
